物件與純值


Posted by hoyi-23 on 2021-06-21

物件與純值最大的差別就是: 純值不能新增屬性

物件新增屬性

var family = {};
family.name = 'Ray';
console.log(family); //物件
console.log(family['name']); // 'Ray'

純值新增屬性 (錯誤)

var num = 10;
console.log(num); //10
num.name = 'Ray';
console.log(num.name); //undefined

純值不允許新增屬性

JavaScript 只有兩種型別: 物件 與 純值

純值:

  1. String
  2. Boolean
  3. Number
  4. Undefined
  5. Null

#物件 #純值







Related Posts

[Power BI] 讀書會 #4 Analysis Services 概念(3)

[Power BI] 讀書會 #4 Analysis Services 概念(3)

Day 34 - Type Hints & Quizzler Game

Day 34 - Type Hints & Quizzler Game

Day03  自製收費廣告版位 - 使用 react-intersection-observer

Day03 自製收費廣告版位 - 使用 react-intersection-observer


Comments